import random as r
legal_x=[0,10]
legal_y=[0,10]
class Wugui:
    def __init__(self):
        self.HP=100
        self.x=r.randint(legal_x[0],legal_x[1])
        self.y=r.randint(legal_y[0],legal_y[1])
        
    def eat(self):
        self.HP+=20
        if self.HP >100:
            self.HP=100
            
    def move(self):
        new_x=self.x+r.choice([1,2,-1,-2])
        new_y=self.y+r.choice([1,2,-1,-2])
        if new_x<legal_x[0]:
            self.x=legal_x[0]-(new_x-legal_x[0])
        elif new_x>legal_x[1]:
            self.x=legal_x[1]-(new_x-legal_x[1])
        else :
            self.x=new_x
            
        if new_y<legal_y[0]:
            self.y=legal_y[0]-(new_y-legal_y[0])
        elif new_y>legal_y[1]:
            self.y=legal_y[1]-(new_y-legal_y[1])
        else :
            self.y=new_y
            
        self.HP-=1
            
        return (self.x,self.y)
        
class Yu:
    def __init__(self):
        self.x=r.randint(legal_x[0],legal_x[1])
        self.y=r.randint(legal_y[0],legal_y[1])
    def move(self):
        new_x=self.x+r.choice([1,-1])
        new_y=self.y+r.choice([1,-1])
        if new_x<legal_x[0]:
            self.x=legal_x[0]-(new_x-legal_x[0])
        elif new_x>legal_x[1]:
            self.x=legal_x[1]-(new_x-legal_x[1])
        else :
            self.x=new_x
            
        if new_y<legal_y[0]:
            self.y=legal_y[0]-(new_y-legal_y[0])
        elif new_y>legal_y[1]:
            self.y=legal_y[1]-(new_y-legal_y[1])
        else :
            self.y=new_y
            
        return (self.x,self.y)

wugui = Wugui()
yu=[]
for i in range(10):
    new_yu=Yu()
    yu.append(new_yu)

while True:
    if not len(yu):
        print('鱼吃完了,游戏结束！')
        print('乌龟现在在x：%d,y:%d'%(wugui.x,wugui.y))
        break
    if not wugui.HP:
        print('乌龟死了,游戏结束！')
        for j in range(len(yu)):
            print('鱼现在在x:%d,y:%d'%(yu[j].x,yu[j].y))
        break

    pos = wugui.move()
    #这边为什么要用pos 把移动交给迭代器？
    
    for each_yu in yu[:]:
        if each_yu.move() == pos :
            wugui.eat()
            yu.remove(each_yu)
            print("有一条鱼儿被吃掉了...\n乌龟现在%d血,还剩%d条鱼"% (wugui.HP,len(yu)))
